//
//  BHCompetitionSecView.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/6/15.
//

import UIKit

@objc protocol BHCompetitionSecViewDelegate: NSObjectProtocol {
    func changeTypeDidSelectAct(type: Int)
}

class BHCompetitionSecView: UIView {
    
    @IBOutlet var secBtnArray: [UIButton]!
    fileprivate var remarkBtn: UIButton!
    
    var delegate: BHCompetitionSecViewDelegate?
    
    
    static func loadFromXib() -> BHCompetitionSecView {
        let viewArray = Bundle.main.loadNibNamed("BHCompetitionSecView", owner: nil, options: nil)
        let view: BHCompetitionSecView = viewArray![0] as! BHCompetitionSecView
        return view
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.remarkBtn = self.secBtnArray.first
        self.toSelect(sender: self.remarkBtn)
    }
    
    @IBAction func changeAct(_ sender: UIButton) {
        if sender.isSelected == true {
            return
        }
        
        self.toSelect(sender: sender)
        self.toNormal(sender: self.remarkBtn)
        
        self.remarkBtn = sender
        
        self.delegate?.changeTypeDidSelectAct(type: sender.tag-100)
    }
    
    
    private func toSelect(sender: UIButton) {
        sender.isSelected = true
        sender.titleLabel?.font = .systemFont(ofSize: 14, weight: .bold)
    }
    
    private func toNormal(sender: UIButton) {
        sender.isSelected = false
        sender.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
    }
    
    
    static var headerHeight: CGFloat {
        get {
            return 53
        }
    }
}
